package bsi.vn.Data;

import java.util.ArrayList;

import bsi.vn.FirstApp.R;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ProvinceSpinnerAdapter extends ArrayAdapter<ProvinceData>{

	private Activity context;
    ArrayList<ProvinceData> data = null;

    public ProvinceSpinnerAdapter(Activity context, int resource, ArrayList<ProvinceData> data)
    {
        super(context, resource, data);	
        this.context = context;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {   // Ordinary view in Spinner, we use android.R.layout.simple_spinner_item
        //return super.getView(position, convertView, parent);   
    	return getProvinceView(position, convertView, parent);
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent)
    {   
    	return getProvinceView(position, convertView, parent);
    }
    
    public View getProvinceView(int position, View convertView, ViewGroup parent)
    {   // This view starts when we click the spinner.
        View row = convertView;
        if(row == null)
        {
            LayoutInflater inflater = context.getLayoutInflater();
            row = inflater.inflate(R.layout.spinner_row, parent, false);
        }

        ProvinceData item = data.get(position);

        //if(item != null)
        //{   
        	TextView tvId = (TextView) row.findViewById(R.id.srtvId);
            TextView tvName = (TextView) row.findViewById(R.id.srtvName);
            
            tvId.setText(String.valueOf(item.getId()));
            tvName.setText(item.getName());
        //}
        return row;
    }
}
